import {
	BaseUrl
} from '@/config/const.js'
import {
	get_token
} from '@/auth/token'
// 文件上传
export async function commonUploadFile(data) {
	return new Promise(function(resolve, reject) {
		uni.uploadFile({
			url: BaseUrl + '/ps/common/batch/upload', //上传图片api
			filePath: data.path || data,
			name: 'file', // 后端接收的字段
			formData:{
				dir: 'flies',
				file: data
			},
			header: {
				"Content-Type": "multipart/form-data",
				'X-Access-Token': get_token()
			},
			success: (res) => {
				console.log(res, 'success')
				resolve(res)
			},
			fail: (res) => {
				console.log(res, 'fail')
				reject(res)
			}
		});
	});
}
// 文件上传
export async function commonUploadFile2(data,type,name) {
	return new Promise(function(resolve, reject) {
		uni.uploadFile({
			url: BaseUrl + `/ps/common/uploadByName?type=${type}&fileName=${name}`, //上传图片api
			filePath: data.path || data,
			name: 'file', // 后端接收的字段
			formData:{
				dir: 'images',
				file: data
			},
			header: {
				"Content-Type": "multipart/form-data",
				'X-Access-Token': get_token()
			},
			success: (res) => {
				resolve(res)
			},
			fail: (res) => {
				reject(res)
			}
		});
	});
}
export async function commonUploadPic(data,type) {
	return new Promise(function(resolve, reject) {
		uni.uploadFile({
			url: BaseUrl + `/ps/common/upload?type=${type}`, //上传图片api
			filePath: data.path || data,
			name: 'file', // 后端接收的字段
			formData:{
				dir: 'images',
				file: data
			},
			header: {
				"Content-Type": "multipart/form-data",
				'X-Access-Token': get_token()
			},
			success: (res) => {
				resolve(res);
			},
			fail: (res) => {
				reject(res)
			}
		});
	});
}
export function uploadFile(tempFilePath) {
	return new Promise(function(resolve, reject) {
		uni.uploadFile({
			url: BaseUrl + '/ps/common/upload', //仅为示例，非真实的接口地址
			header: {
				"Content-Type": "multipart/form-data",
				'X-Access-Token': get_token()
			},
			filePath: tempFilePath,
			name: 'file',
			formData:{
				dir: 'files',
				file: data
			},
			success: (res) => {
				// console.log(res, 'uploadFileSuccess')
				resolve(JSON.parse(res.data).result);
			},
			fail: (res) => {
				// console.log(res, 'uploadFileFail')
				reject(res)
			}
		});
	});
}